#include<stdio.h>
int main() {
	int big, arr_big[50] = { 0 }, mid, arr_mid[50] = { 0 }, little, arr_little[50] = { 0 }, n, T, count;
	scanf("%d", &T);
	while (T--) {
		count = 0;
		scanf("%d", &n);
		//n元钱 n只鸡,问有多少种买法
		//公鸡big(5元一只)   母鸡mid（三元一只） 小鸡little（一元三只）
		for (big = 0; big <= n / 5; big++) {
			if (!((n - 7 * big) % 4)) {
				mid = (n - 7 * big) / 4;
				little = n - big - mid;
				if (mid >= 0 && (((5 * big + 3 * mid + little / 3) == n) && (little % 3 == 0)) && (big + mid + little == n)) {
					arr_big[count] = big;
					arr_mid[count] = mid;
					arr_little[count] = little;
					count++;
				}
			}
		}
		printf("%d\n", count);
		for (int i = 0; i < count; i++) {
			printf("%d %d %d\n", arr_big[i], arr_mid[i], arr_little[i]);
		}
		
	}
	 return 0;
}